package com.cdfy.jwtdemo;

import com.cdfy.bean.BaseBean;
import com.cdfy.bean.TokenBean;
import com.google.gson.Gson;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {
    @ResponseBody
    @ExceptionHandler(Exception.class)
    public String handleException(Exception e) {
        String msg = e.getMessage();
        if (msg == null || msg.equals("")) {
            msg = "服务器出错";
        }
        BaseBean baseBean = new BaseBean();
        baseBean.setErrCode(1);
        baseBean.setMessage(msg);
        return new Gson().toJson(baseBean);
    }
}
